package org.spiderflow.oss.function.extension;

import org.jsoup.Jsoup;
import org.jsoup.nodes.Element;
import org.spiderflow.executor.FunctionExtension;
import org.spiderflow.oss.model.Oss;
import org.spiderflow.oss.model.OssFile;
import org.spiderflow.oss.service.OssService;
import org.spiderflow.oss.utils.OSSUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class OssReplaceUrlFunctionExtension implements FunctionExtension {

    private static OssService ossService;

    @Autowired
    private void setOssMapper(OssService ossService) {
        OssReplaceUrlFunctionExtension.ossService = ossService;
    }
    @Override
    public Class<?> support() {
        return Element.class;
    }

    public static OssFile replaceFileUrl(Element element, String ossId, String filePath) throws Exception {
        Oss oss = ossService.getOss(ossId);
        if(null != oss) {
            //ExtractUtils.getValueByXPath(element, xpath);
            //return OSSUtil.uploadFileToOss(oss, Jsoup.connect(url).ignoreContentType(true).execute().bodyAsBytes(), filePath);
        }
        return null;
    }
}
